import {fhirSearchApi, fhirHistoryApi, fhirDeleteApi} from "../../api/modules/fhirApi";
import {createEncounterApi, updateEncounterApi} from "../../api/modules/encApi";

export default {
  state: {
    encounterList: []
  },
  mutations: {
    setEncounterList(state, data) {
      state.encounterList = data;
    }
  },
  actions: {
    getEncounterList({commit, rootState}, params) {
      return fhirSearchApi(params).then(res => {
        console.log(res);
        commit('setEncounterList', res.data.entry ? res.data.entry : [{resource: res.data}])
      }).catch(res => {
        commit('setEncounterList', []);
      })
    },
    getHistoryEncounterList({commit, rootState}, params) {
      return fhirHistoryApi(params).then(res => {
        commit('setEncounterList', res.data.entry ? res.data.entry : [{resource: res.data}])
      })
    },
    updateEncounter({commit, rootState}, params) {
      return updateEncounterApi(params);
    },
    createEncounter({commit, rootState}, params) {
      return createEncounterApi(params);
    },
    deleteEncounter({commit, rootState}, params) {
      return fhirDeleteApi(params);
    }
  }
}
